//
//  ViewController.m
//  EmojiExample
//
//  Created by jianyong.wang on 2017/6/5.
//  Copyright © 2017年 jianyong.wang. All rights reserved.
//

#import "ViewController.h"
#import "JYInputView.h"
#import "macros.h"
#import "JYTableViewCell.h"
#import "JYLayoutConfig.h"
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableview;
@property (nonatomic,strong) JYInputView * emojiView;
@property (nonatomic,strong) NSMutableArray * datasource;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.datasource = [NSMutableArray array];
     [self.tableview registerNib:[UINib nibWithNibName:@"JYTableViewCell" bundle:nil] forCellReuseIdentifier:NSStringFromClass([JYTableViewCell class])];
    self.tableview.delegate = self;
    self.tableview.dataSource = self;
    //创建下方输入框
    _emojiView = [[JYInputView alloc]initWithFrame:(CGRect){0,kScreenHeight - 60,kScreenWidth,270}];
    [self.view addSubview:_emojiView];
    __weak typeof(self)Weakself = self;
    _emojiView.send = ^(NSString * msg){
        [Weakself sendMessageString: msg];
    };
    // Do any additional setup after loading the view, typically from a nib.
}
-(void)sendMessageString:(NSString *)string
{
    [self.datasource addObject:string];
    [self.tableview reloadData];
    [self.tableview scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:self.datasource.count - 1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.datasource.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    JYTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"JYTableViewCell" forIndexPath:indexPath ];
    [cell.titleLabel jy_setText:self.datasource[indexPath.row]];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return  [JYLayoutConfig m80AttributeLabelWithText:self.datasource[indexPath.row] cgsize:CGSizeMake(kScreenWidth, MAXFLOAT)].height + 10;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
